package com.android.Translator.View;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;

import com.android.Translator.R;
import com.android.Translator.Presenter.TranslatorPresenter;
import com.android.Translator.View.utils.ViewUtils;

public class Main extends Activity implements OnClickListener{
	private ImageButton m_ImgBtnExit, m_ImgBtnInfo;
	private Button m_BtnLearn, m_BtnAddWord, m_BtnDictionary;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		initView();
	}
	
	private void initView()
	{
		DisplayMetrics displaymetrics = new DisplayMetrics();
    	getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
   		
   		int width = displaymetrics.widthPixels;
   		int btnWidth = (int) (width/1.6);

		m_ImgBtnExit = (ImageButton) findViewById(R.id.MM_ImgExit);
		m_ImgBtnExit.setOnClickListener(this);
		m_ImgBtnInfo = (ImageButton) findViewById(R.id.MM_ImgInfo);
		m_ImgBtnInfo.setOnClickListener(this);
		
		m_BtnLearn   = (Button) findViewById(R.id.MM_btnLearn);
		m_BtnLearn.setOnClickListener(this);
		m_BtnLearn.setWidth(btnWidth);
		
		m_BtnAddWord = (Button) findViewById(R.id.MM_btnAddWord);
		m_BtnAddWord.setOnClickListener(this);
		m_BtnAddWord.setWidth(btnWidth);
		
		m_BtnDictionary = (Button) findViewById(R.id.MM_btnTranslate);
		m_BtnDictionary.setOnClickListener(this);
		m_BtnDictionary.setWidth(btnWidth);
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_BACK)
			ViewUtils.ShowAlertDialog(Main.this, null,ViewUtils.ACTION_EXIT, 
										getString(R.string.TITLE_ALERT_DIALOG), 
										getString(R.string.MESSAGE_ALERT_DIALOG));
		return super.onKeyDown(keyCode, event);
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		int id = v.getId();
		Intent i;
		switch (id)
		{
		case R.id.MM_ImgExit:
			ViewUtils.ShowAlertDialog(Main.this, null, ViewUtils.ACTION_EXIT, 
													getString(R.string.TITLE_ALERT_DIALOG), 
													getString(R.string.MESSAGE_ALERT_DIALOG));
			break;
		case R.id.MM_ImgInfo:
			break;
		case R.id.MM_btnLearn:
		{
			//if (TranslatorPresenter.getMyWords(this).size() > 0)
				i = new Intent(getApplicationContext(), SelectTimeActivity.class);
				startActivity(i);
			//}
			//else
			//{
				
				//Activity AddWordAct = new AddWordToLearn();;
				/*ViewUtils.ShowAlertDialog(Main.this, AddWordAct , ViewUtils.ACTION_LAUNCH, 	
																		getString(R.string.TITLE_ALERT_DIALOG), 
																		getString(R.string.MESSAGE_DONT_HAVE_WORD));*/
			//}
			break;
		}
		case R.id.MM_btnAddWord:
			i = new Intent(getApplicationContext(), AddWordToLearn.class);
			startActivity(i);
			break;
		case R.id.MM_btnTranslate:
			i = new Intent(getApplicationContext(), TranslatorActivity.class);
			startActivity(i);
			break;
		}
	}
}
